#include "mainwindow.h"

#include <QApplication>
#include <QDebug>
#include <QLabel>
#include <QLayout>
#include <QSizePolicy>

#include <KWindowEffects>

//#include <ukuistylehelper/ukuistylehelper.h>

#include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/registry.h>
#include <KWayland/Client/server_decoration.h>
#include <KWayland/Server/global.h>

using namespace KWayland::Client;

int main(int argc, char *argv[])
{
    qputenv("QT_QPA_PLATFORM", QByteArrayLiteral("wayland"));
    QApplication a(argc, argv);
    MainWindow w;

    kdk::UkuiStyleHelper *sss = kdk::UkuiStyleHelper::self();
    sss->removeHeader(&w);
    KWindowEffects::enableBlurBehind(w.winId(), true);
    w.init();

    ConnectionThread *connection = ConnectionThread::fromApplication();
    Registry registry;
    registry.create(connection);

    QObject::connect(
        &registry,
        &Registry::interfacesAnnounced,
        &a,
        [&registry, &w] {
            const bool hasServersideDecoManager = registry.hasInterface(Registry::Interface::ServerSideDecorationManager);
            QLabel *infoLabel = new QLabel(&w);
            if (hasServersideDecoManager) {
                infoLabel->setText(QStringLiteral("Compositor provides a serverSideDecoMgr"));
            } else {
                infoLabel->setText(QStringLiteral("Compositor does not provide a KeyState"));
            }
            infoLabel->adjustSize();

            w.show();
        },
        Qt::QueuedConnection);
    registry.setup();

    return a.exec();
}
